package com.leetcode.contest;

/**
 * @author `RKC`
 * @date 2021/11/14 10:31
 */
public class LC5926买票需要的时间 {

    public static int timeRequiredToBuy(int[] tickets, int k) {
        int answer = 0;
        while (tickets[k] > 0) {
            for (int i = 0; i < tickets.length; i++) {
                if (tickets[i] > 0) {
                    answer++;
                    tickets[i]--;
                    if (tickets[k] == 0) return answer;
                }
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        int[] tickets = {84, 49, 5, 24, 70, 77, 87, 8};
        int k = 3;
//        int[] tickets = {3, 1, 2};
//        int k = 2;
        System.out.println(timeRequiredToBuy(tickets, k));
    }
}
